/**
  * Author: Mei
  * Date: 2021-01-13 10:21
  * Description: chrono库
  * chrono库主要包含三种类型：时间间隔duration、时钟clocks和时间点time point
  *
  */
#include <iostream>
#include <chrono>

using namespace std;

int main() {
    //1、记录时长的duration
    //duration表示一段时间间隔，用来记录时间长度，可以表示几秒、几分钟或者几个小时的时间间隔。
    std::chrono::milliseconds ms{3};
    std::chrono::microseconds us = 2 * ms;
    std::chrono::seconds se{1};
    std::chrono::duration<double, std::ratio<1, 30>> hz{3.5}; //分数

    cout << "3 ms duration has " << ms.count() << " ticks\n" << "6000 us duration has " << us.count() << " ticks\n"
         << endl;

    std::chrono::minutes mi1{10};
    std::chrono::seconds se1{60};
    std::chrono::seconds se2 = mi1 - se1;
    cout << se2.count() << endl;
    cout << chrono::duration_cast<std::chrono::minutes>(se2).count() << endl;

    std::chrono::duration<double, std::ratio<9, 7>> d1(3);
    std::chrono::duration<double, std::ratio<6, 5>> d2(1);
    auto d3 = d1 - d2;
    cout << typeid(d3).name() << endl;
    cout << d3.count() << endl;
    return 0;
}